<?php
/**
 * View  LaFabbrica.org
 * 
 * @author     luigi.pastore (gigi@la-fabbrica.org)
 * @created    17-mag-2011
 * @package    LaFabbrica
 * @copyright  Copyright (c) 2011 Luigi Pastore
 */
?>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
    //<![CDATA[
     
    $(document).ready(function()
    {
        $('div.tab-content').hide();
        $("ul.tabs li:first").addClass("active").show();
        $('li.tabs a').click(function(){
            $('div.tab-content').hide();
            $("ul.tabs li a").removeClass("active"); //Remove any "active" class
            $(this).addClass("active"); //Add "active" class to selected tab
            var href = $(this).attr('href');
            $('div#'+href).show();
        });
        
        $('li#tab1 a').trigger('click');
        
        $("#map-frame").ready(function()
        {
        
            geocoder = new google.maps.Geocoder();
            /* Info Locale */
            var address	= "<?php echo $this->data['contact_name'] .','. $this->data['contact_street'] .','.$this->data['contact_street_number'] .','. $this->data['contact_city'] .' ('.$this->province[$this->data['contact_province_id']]['province_long_name'] .')' ?>";
            var title	= "<?php echo $this->data['contact_name']?>";

            var myOptions = {
                zoom: 16,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };

            /* Istanzia la mappa */
            var map = new google.maps.Map(document.getElementById("map-frame"),myOptions);

            geocoder.geocode( { 'address': address}, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    map.setCenter(results[0].geometry.location);
                    var marker = new google.maps.Marker({
                        map: map,
                        position: results[0].geometry.location,
                        animation: google.maps.Animation.DROP,
                        title: title
                    });
                } else {
                    alert("Geocode fallito: " + status);
                }
            });    
        });
    });

    //]]>
</script>
<div class="info">
    <h2>Dettagli Contatto</h2>
    <div>...</div>
</div>
<div id="content">
<div id="summary" class="contact">
        <div class="head contact">
            <h2><?php echo $this->data['contact_firstname']?> <?php echo $this->data['contact_lastname']?></h2>
        </div>
        <div class="body tabbed">
            <div id="tabbed-info" class="tab1">
                <ul class="tabs">
                    <li id="tab1" class="tabs"><a href="#info">Generale</a></li>
                    <li id="tab2" class="tabs"><a href="#roles">Ruoli</a></li>
                    <li id="tab3" class="tabs"><a href="#map">Indirizzo</a></li>
                </ul>

                <div id="info" class="tab-content">
                    <table cellspacing="0" class="table">
                        <tbody>
                            <tr>
                                <th>Nome:</th>
                                <td>
                                    <strong>
                                    <?php echo $this->data['contact_firstname']?> <?php echo $this->data['contact_lastname']?>
                                    </strong>
                                </td>
                            </tr>
                            <tr>
                                <th>Email Principale:</th>
                                <td><?php echo $this->data['contact_email']?></td>
                            </tr>
                            <tr>
                                <th>Tel Principale:</th>
                                <td><?php echo $this->data['contact_phone']?></td>
                            </tr>
                            <tr class="break">
                                <td colspan="2">&nbsp;</td>
                            </tr>
                            <tr>
                                <th>Email 2:</th>
                                <td><?php echo $this->data['contact_email2']?></td>
                            </tr>
                            <tr>
                                <th>Email 3:</th>
                                <td><?php echo $this->data['contact_email3']?></td>
                            </tr>
                            <tr>
                                <th>Tel Lavoro:</th>
                                <td><?php echo $this->data['contact_work']?></td>
                            </tr>
                            <tr>
                                <th>Tel Privato:</th>
                                <td><?php echo $this->data['contact_mobile']?></td>
                            </tr>
                            <tr>
                                <th>Fax:</th>
                                <td><?php echo $this->data['contact_fax']?></td>
                            </tr>
                            <tr class="break">
                                <td colspan="2">&nbsp;</td>
                            </tr>                            
                            <tr>
                                <th>Note:</th>
                                <td><?php echo $this->data['contact_notes']?></td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div id="roles" class="tab-content">
                    <?php if( count( $this->data['contact_locations'] ) OR count( $this->data['contact_locations'] )  ): ?>
                        <!--	Locations	-->
                        <?php if( count( $this->data['contact_locations'] ) ): ?>
                        <table class="contact-roles table">
                            <?php foreach($this->data['contact_locations'] AS $role ) :?>
                            <tr>
                                <td>
                                    <div class="box">
                                        <span class="edit-link">
                                            <a href="/admin/location/contatti/id/<?php echo $role['location_id'] ?>" title="Modifica Contatti Location">&nbsp;</a>
                                        </span>
                                        <span class="type location">location</span>
                                        <span class="title"><?php echo $role['location_name']?></span>
                                        <span class="role"><?php echo $this->contact_roles[$role['fab_contacts_role']]?></span>
                                    </div>
                                </td>
                            </tr>
                            <?php endforeach; ?>

                        <?php endif; ?>
                        <!--	Fine Locations	-->
                        <!--	Partners	-->
                        <?php if( count( $this->data['contact_partners'] ) ): ?>

                            <?php foreach($this->data['contact_partners'] AS $role ) :?>
                            <tr>
                                <td>
                                    <div class="box">
                                        <span class="edit-link">
                                            <a href="/admin/partners/contatti/id/<?php echo $role['partner_id'] ?>" title="Modifica Contatti Partner">&nbsp;</a>
                                        </span>
                                        <span class="type partner">partner</span>
                                        <span class="extra">extra</span>
                                        <span class="title"><?php echo $role['partner_name']?></span>
                                        <span class="role"><?php echo $this->contact_roles[$role['fab_contacts_role']]?></span>
                                    </div>
                                </td>
                            </tr>
                            <?php endforeach; ?>

                        <?php endif; ?>
                        <!--	Fine Partners	-->

                    <?php endif; ?>
                    </table>                    
                </div>
                <div id="map" class="tab-content">
                    <table cellspacing="0" class="table">
                        <tbody>
                            <tr>
                                <th>Indirizzo</th>
                                <td>
                                <?php 
                                $address = NULL;

                                if( $this->data['contact_street'] != '' )
                                    $address .= $this->data['contact_street'] .', ';

                                if( $this->data['contact_street_number'] != '' )
                                    $address .= 'N&deg; '. $this->data['contact_street_number'] .'<br /> ';

                                if( $this->data['contact_loc'] != '' )
                                    $address .= 'Localit&aacute; '. $this->data['contact_loc'] .'<br />';

                                if( $this->data['contact_cap'] != '' )
                                    $address .= $this->data['contact_cap'];

                                if( $this->data['contact_city'] != '' )
                                    $address .= ' <strong>'. strtoupper( $this->data['contact_city'] ) .'</strong> ';

                                if( $this->data['contact_prov'] != '' )
                                    $address .= '('. $this->province[$this->data['contact_prov']]['short_name'] .')';
                            
                                if( $address !== NULL )
                                {
                                    echo $address;
                                }
                                ?>
                                </td>
                            </tr>
                            <tr class="break">
                                <td colspan="2">&nbsp;</td>
                            </tr>
                            <tr>
                                <?php if( $address !== NULL ) : ?>
                                <td colspan="2" id="map-container">
                                    <div id="map-frame">
                                        <!-- Mappa -->
                                    </div>
                                </td>
                                <?php else: ?>
                                <td colspan="2"><i>Non ci sono abbastanza informazioni sull'indirizzo...</i></td>
                                <?php endif; ?>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>    
</div>
<br style="clear: both;" />
<form class="fab">
    <ul>
        <li class="section">
            <h3>Cosa vuoi fare?</h3>
        </li>
        <li class="addnew center">
            <a id="" class="button" href="/admin/contatti/info/id/<?php echo $this->data['contact_id'] ?>">
                <img src="/images/admin/16x16/edit.png" />Modifica Contatto
            </a>
            <a id="" class="button" href="/admin/contatti/associa/id/<?php echo $this->data['contact_id'] ?>">
                <img src="/images/admin/16x16/link.png" />Associa Contatto
            </a>
            <a id="new" class="button" href="/admin/contatti/info">
                <img src="/images/admin/16x16/add-new.png" />Aggiungi Nuovo Contatto
            </a>
            <a id="" class="button" href="/admin/contatti/rubrica">
                <img src="/images/admin/contact-icon.png" />Torna a Rubrica
            </a>
        </li>
    </ul>
</form>

